package com.mmlc.businessutils;

import android.content.Intent;
import android.view.View;

import com.androidnetframe.httputil.BaseRequestFilterLayer;
import com.androidnetframe.responsejavabean.RequestError;
import com.mmlc.meimei.lichengkongjian.been.OrderButtonBean;
import com.mmlc.meimei.lichengkongjian.classify.OrderFormActivity;
import com.mmlc.meimei.lichengkongjian.mine.ActivityShowGoPay;
import com.mmlc.network.filter.GoPayRequestFilter;
import com.mmlc.network.responsebean.GoPayResponseBean;
import com.mmlc.utils.ToastUtils;

/**
 * Created by Administrator on 2016/8/16 0016.
 */
public class GoPayRequest {
    OrderListUtils orderListUtils;
    OrderButtonBean buttonBean;
    public GoPayRequest(OrderListUtils orderListUtils) {
        this.orderListUtils = orderListUtils;
        buttonBean = orderListUtils.buttonBean;
    }

    public void goPay(){
        if(buttonBean.orderType == 2 ){
            Intent intent = new Intent(buttonBean.activity, OrderFormActivity.class);
            intent.putExtra("oderId",buttonBean.orderId);
            intent.putExtra("type",buttonBean.orderType);
            buttonBean.activity.startActivity(intent);

        } else {

            goPayDetail(buttonBean.orderId);

        }/*else if(buttonBean.orderType == 3){
            if(buttonBean.isDetail){
                final DetailConfirmDialog detaiDialog = new DetailConfirmDialog(buttonBean.context,R.style.dialog, buttonBean.detailSuborder);
                detaiDialog.show();
                detaiDialog.setClicklistener(new DetailConfirmDialog.ClickListenerInterface() {
                    @Override
                    public void doSuba() {
                        goPayDetail(buttonBean.detailSuborder.get(0).getId());
                        detaiDialog.dismiss();
                    }

                    @Override
                    public void doSubb() {
                        goPayDetail(buttonBean.detailSuborder.get(1).getId());
                        detaiDialog.dismiss();
                    }

                    @Override
                    public void doCancel() {
                        detaiDialog.dismiss();
                    }
                });

            }else {
                final ConfirmDialog dialog = new ConfirmDialog(buttonBean.context, R.style.dialog, buttonBean.suborder);
                dialog.show();
                dialog.setClicklistener(new ConfirmDialog.ClickListenerInterface() {
                    @Override
                    public void doSuba() {
                        goPayDetail(buttonBean.suborder.get(0).getId());
                        dialog.dismiss();
                    }

                    @Override
                    public void doSubb() {
                        goPayDetail(buttonBean.suborder.get(1).getId());
                        dialog.dismiss();
                    }

                    @Override
                    public void doCancel() {
                        dialog.dismiss();
                    }
                });
            }
        }*/

    }

    public void goPayDetail(String orderId) {
        GoPayRequestFilter filter = new GoPayRequestFilter(buttonBean.activity);
        filter.requestBean.method = "goPay";
        filter.requestBean.order_id = orderId;
        filter.requestBean.pay_code = buttonBean.payType;
        filter.offerErrorParams(buttonBean.rootView);
        filter.isTransparence = true;
        filter.sendRequest(new BaseRequestFilterLayer.AccessResultFromFilter<GoPayResponseBean>() {

            @Override
            public void onSuccess(GoPayResponseBean result) {
                Intent intent = new Intent(buttonBean.activity, ActivityShowGoPay.class);
                intent.putExtra("order_id", result.getData().getOrder_id());
                intent.putExtra("order_price", result.getData().getOrder_price());
                intent.putExtra("pay_name",result.getData().getPay_name());
                intent.putExtra("pay_code", result.getData().getPay_code());
                intent.putExtra("title", result.getData().getTitle());
                intent.putExtra("body", result.getData().getBody());
                intent.putExtra("timestamp", result.getData().getTimestamp());
                intent.putExtra("notify_url", result.getData().getNotify_url());
                intent.putExtra("pay_url", result.getData().getPay_url());
                intent.putExtra("ext1",result.getData().getExt1());
                intent.putExtra("gift_score",result.getData().getGift_score());
                buttonBean.activity.startActivity(intent);
            }

            @Override
            public void onFailed(View errorLayout, RequestError serverError, int failedType) {
                ToastUtils.showToast(serverError.mess);
            }
        });
    }
}
